package com.example.a053checkbox_switch_radiobutton_imageview; // 请根据实际包名修改

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RadioGroup;

public class ImageViewActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
    private ImageView mImageView;
    private RadioGroup mRadioGroup1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_view);
        initView();
    }

    private void initView() {
        mImageView = findViewById(R.id.imageView);
        // 这里假设drawable目录下有cartoon图片资源，需确保资源存在
        mImageView.setImageResource(R.drawable.cartoon);
        mRadioGroup1 = findViewById(R.id.radioGroup1);
        mRadioGroup1.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        if (i == R.id.radioButton1) {
            mImageView.setScaleType(ImageView.ScaleType.MATRIX);
        } else if (i == R.id.radioButton2) {
            mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
        } else if (i == R.id.radioButton3) {
            mImageView.setScaleType(ImageView.ScaleType.FIT_START);
        } else if (i == R.id.radioButton4) {
            mImageView.setScaleType(ImageView.ScaleType.FIT_END);
        } else if (i == R.id.radioButton5) {
            mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        } else if (i == R.id.radioButton6) {
            mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        } else if (i == R.id.radioButton7) {
            mImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        } else if (i == R.id.radioButton8) {
            mImageView.setScaleType(ImageView.ScaleType.CENTER);
        }
    }

}